﻿using System;

namespace HslCommunication.Core
{
	/// <summary>
	/// 一个数据范围管理的的类型对象，可以方便的管理一个数据值的最大值，最小值，平均值信息。<br />
	/// A type object managed by a data range can conveniently manage the maximum, minimum, and average information of a data value.
	/// </summary>
	// Token: 0x0200012C RID: 300
	public struct ValueLimit
	{
		/// <summary>
		/// 当前的数据的最大值<br />
		/// The maximum value of the current data
		/// </summary>
		// Token: 0x17000540 RID: 1344
		// (get) Token: 0x0600196D RID: 6509 RVA: 0x00080088 File Offset: 0x0007E288
		// (set) Token: 0x0600196E RID: 6510 RVA: 0x00080090 File Offset: 0x0007E290
		public double MaxValue { get; set; }

		/// <summary>
		/// 当前的数据的最小值<br />
		/// The minimum value of the current data
		/// </summary>
		// Token: 0x17000541 RID: 1345
		// (get) Token: 0x0600196F RID: 6511 RVA: 0x00080099 File Offset: 0x0007E299
		// (set) Token: 0x06001970 RID: 6512 RVA: 0x000800A1 File Offset: 0x0007E2A1
		public double MinValue { get; set; }

		/// <summary>
		/// 当前的数据的平均值<br />
		/// Average value of current data
		/// </summary>
		// Token: 0x17000542 RID: 1346
		// (get) Token: 0x06001971 RID: 6513 RVA: 0x000800AA File Offset: 0x0007E2AA
		// (set) Token: 0x06001972 RID: 6514 RVA: 0x000800B2 File Offset: 0x0007E2B2
		public double Average { get; set; }

		/// <summary>
		/// 当前的数据的起始值<br />
		/// The starting value of the current data
		/// </summary>
		// Token: 0x17000543 RID: 1347
		// (get) Token: 0x06001973 RID: 6515 RVA: 0x000800BB File Offset: 0x0007E2BB
		// (set) Token: 0x06001974 RID: 6516 RVA: 0x000800C3 File Offset: 0x0007E2C3
		public double StartValue { get; set; }

		/// <summary>
		/// 当前的数据的当前值，也是最后一次更新的数据值<br />
		/// The current value of the current data is also the last updated data value
		/// </summary>
		// Token: 0x17000544 RID: 1348
		// (get) Token: 0x06001975 RID: 6517 RVA: 0x000800CC File Offset: 0x0007E2CC
		// (set) Token: 0x06001976 RID: 6518 RVA: 0x000800D4 File Offset: 0x0007E2D4
		public double Current { get; set; }

		/// <summary>
		/// 当前的数据的更新总个数<br />
		/// The total number of current data updates
		/// </summary>
		// Token: 0x17000545 RID: 1349
		// (get) Token: 0x06001977 RID: 6519 RVA: 0x000800DD File Offset: 0x0007E2DD
		// (set) Token: 0x06001978 RID: 6520 RVA: 0x000800E5 File Offset: 0x0007E2E5
		public int Count { get; set; }

		/// <summary>
		/// 重新设置当前的最新值，然后计算新的最大值，最小值，平均值等信息<br />
		/// Reset the current latest value, and then calculate the new maximum, minimum, average and other information
		/// </summary>
		/// <param name="value">新的数据值信息</param>
		/// <returns>新的值对象</returns>
		// Token: 0x06001979 RID: 6521 RVA: 0x000800F0 File Offset: 0x0007E2F0
		public ValueLimit SetNewValue(double value)
		{
			bool flag = double.IsNaN(value);
			if (!flag)
			{
				bool flag2 = this.Count == 0;
				if (flag2)
				{
					this.MaxValue = value;
					this.MinValue = value;
					this.Count = 1;
					this.Current = value;
					this.Average = value;
					this.StartValue = value;
				}
				else
				{
					bool flag3 = value < this.MinValue;
					if (flag3)
					{
						this.MinValue = value;
					}
					bool flag4 = value > this.MaxValue;
					if (flag4)
					{
						this.MaxValue = value;
					}
					this.Current = value;
					this.Average = ((double)this.Count * this.Average + value) / (double)(this.Count + 1);
					int count = this.Count;
					this.Count = count + 1;
				}
			}
			return this;
		}

		/// <inheritdoc />
		// Token: 0x0600197A RID: 6522 RVA: 0x000801C6 File Offset: 0x0007E3C6
		public override string ToString()
		{
			return string.Format("Avg[{0}]", this.Current);
		}

		/// <summary>
		/// 判断是否相等
		/// </summary>
		/// <param name="value1">第一个数据值</param>
		/// <param name="value2">第二个数据值</param>
		/// <returns>是否相同</returns>
		// Token: 0x0600197B RID: 6523 RVA: 0x000801E0 File Offset: 0x0007E3E0
		public static bool operator ==(ValueLimit value1, ValueLimit value2)
		{
			bool flag = value1.Count != value2.Count;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				bool flag2 = value1.MaxValue != value2.MaxValue;
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = value1.MinValue != value2.MinValue;
					if (flag3)
					{
						result = false;
					}
					else
					{
						bool flag4 = value1.Current != value2.Current;
						if (flag4)
						{
							result = false;
						}
						else
						{
							bool flag5 = value1.Average != value2.Average;
							if (flag5)
							{
								result = false;
							}
							else
							{
								bool flag6 = value1.StartValue != value2.StartValue;
								result = !flag6;
							}
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 判断是否相等
		/// </summary>
		/// <param name="value1">第一个数据值</param>
		/// <param name="value2">第二个数据值</param>
		/// <returns>是否相同</returns>
		// Token: 0x0600197C RID: 6524 RVA: 0x000802A0 File Offset: 0x0007E4A0
		public static bool operator !=(ValueLimit value1, ValueLimit value2)
		{
			return !(value1 == value2);
		}

		/// <inheritdoc />
		// Token: 0x0600197D RID: 6525 RVA: 0x000802BC File Offset: 0x0007E4BC
		public override bool Equals(object obj)
		{
			ValueLimit value;
			bool flag;
			if (obj is ValueLimit)
			{
				value = (ValueLimit)obj;
				flag = true;
			}
			else
			{
				flag = false;
			}
			bool flag2 = flag;
			return flag2 && this == value;
		}

		/// <inheritdoc />
		// Token: 0x0600197E RID: 6526 RVA: 0x000802F8 File Offset: 0x0007E4F8
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}
	}
}
